package cn.yunhe.services.impl;

import cn.yunhe.dao.IAssistantDao;
import cn.yunhe.entity.Assistant;
import cn.yunhe.services.IAssistantServices;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by 孙权庆 on 2018/5/30.
 */
@Service
public class AssistantServices implements IAssistantServices {

    @Resource
    private IAssistantDao assistantDao;

    /**
     * 检查登录
     *
     * @param map
     * @return
     */
    @Override
    public Assistant checkLogin(Map map) {
        return assistantDao.findByAssistantName(map);
    }

    /**
     * 分页
     *
     * @param cond
     * @return
     */
    @Override
    public Page queryListLikeAssistant(Map<String, Object> cond) {
        Page page = new Page();

        //符合记录的总条数
        page.setTotal(assistantDao.getLikeCount(cond));

        //每页大小
        int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));

        //获取当前页
        int currPageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
        page.setPageNum(currPageNum);

        //计算总页数
        page = PageHelper.startPage(currPageNum, pageSize);
        List<Object> list = assistantDao.getLikeAssistant(cond);
        return page;
    }

    @Override
    public List<Object> getListAssistant() {
        return assistantDao.getListAssistant();
    }

    @Override
    public int addAssistant(Assistant assistant) {
        return assistantDao.addAssistant(assistant);
    }

    @Override
    public Assistant getAssistantById(Assistant assistant) {
        return assistantDao.getAssistantById(assistant);
    }

    @Override
    public int updateAssistant(Assistant assistant) {
        return assistantDao.updateAssistant(assistant);
    }

    @Override
    public int deleteAssistant(Assistant assistant) {
        return assistantDao.deleteAssistant(assistant);
    }

}
